package evolution;

public class StatusCollatingResourceVisitor implements ResourceVisitor
{
	VersionedDirectoryTreeStatus status = new VersionedDirectoryTreeStatus();
	private final VersionedResourceLookup lookup;

	public StatusCollatingResourceVisitor(VersionedResourceLookup lookup)
	{
		this.lookup = lookup;
	}

	public void visitDirectory(Directory directory)
	{
		VersionedResource res = lookup.searchElementByPath(directory.getPath());
		if (res == null)
		{
			// TODO: Must represent an un-versioned resource?
		}
		else if (res.getLastModifiedTime() < directory.getLastModifiedTime())
		{
			status.incrementModifiedCount();
		}
	}

	public void visitFile(File file)
	{
		VersionedResource res = lookup.searchElementByPath(file.getPath());
		if (res == null)
		{
			// TODO: Must represent an un-versioned resource?
		}
		else if (res.getLastModifiedTime() < file.getLastModifiedTime())
		{
			status.incrementModifiedCount();
		}
	}

	public VersionedDirectoryTreeStatus getResult()
	{
		return status;
	}

}
